package cn.ds.assets.module.assets.dal.mysql.metadataModelBase;

import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDate;

import cn.ds.assets.framework.common.pojo.PageResult;
import cn.ds.assets.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ds.assets.framework.mybatis.core.mapper.BaseMapperX;
import cn.ds.assets.module.assets.dal.dataobject.metadataModelBase.BaseMetadataModelBaseDO;
import org.apache.ibatis.annotations.Mapper;
import cn.ds.assets.module.assets.controller.admin.metadataModelBase.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 元数据管理-元模型-基础属性 Mapper
 *
 * @author admin
 */
@Mapper
public interface BaseMetadataModelBaseMapper extends BaseMapperX<BaseMetadataModelBaseDO> {

    default PageResult<BaseMetadataModelBaseDO> selectPage(BaseMetadataModelBasePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BaseMetadataModelBaseDO>()
                .eqIfPresent(BaseMetadataModelBaseDO::getCode, reqVO.getCode())
                .likeIfPresent(BaseMetadataModelBaseDO::getName, reqVO.getName())
                .eqIfPresent(BaseMetadataModelBaseDO::getType, reqVO.getType())
                .eqIfPresent(BaseMetadataModelBaseDO::getDataForm, reqVO.getDataForm())
                .eqIfPresent(BaseMetadataModelBaseDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BaseMetadataModelBaseDO::getDesc, reqVO.getDesc())
                .eqIfPresent(BaseMetadataModelBaseDO::getDel, reqVO.getDel())
                .eqIfPresent(BaseMetadataModelBaseDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(BaseMetadataModelBaseDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataModelBaseDO::getUpdateBy, reqVO.getUpdateBy())
                .inIfPresent(BaseMetadataModelBaseDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataModelBaseDO::getId));
    }

    default List<BaseMetadataModelBaseDO> selectList(BaseMetadataModelBaseExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BaseMetadataModelBaseDO>()
                .eqIfPresent(BaseMetadataModelBaseDO::getCode, reqVO.getCode())
                .likeIfPresent(BaseMetadataModelBaseDO::getName, reqVO.getName())
                .eqIfPresent(BaseMetadataModelBaseDO::getType, reqVO.getType())
                .eqIfPresent(BaseMetadataModelBaseDO::getDataForm, reqVO.getDataForm())
                .eqIfPresent(BaseMetadataModelBaseDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BaseMetadataModelBaseDO::getDesc, reqVO.getDesc())
                .eqIfPresent(BaseMetadataModelBaseDO::getDel, reqVO.getDel())
                .eqIfPresent(BaseMetadataModelBaseDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(BaseMetadataModelBaseDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(BaseMetadataModelBaseDO::getUpdateBy, reqVO.getUpdateBy())
                .inIfPresent(BaseMetadataModelBaseDO::getId,reqVO.getIds())
                .orderByDesc(BaseMetadataModelBaseDO::getId));
    }

    @Update("UPDATE assets_metadata_model_base SET deleted = 1, update_time = #{deletedTime} WHERE id = #{id}")
    void updateToDelete(@Param("id") Long id, @Param("deletedTime") LocalDateTime deletedTime);
}
